package pl.register.android.year;

import pl.register.android.group.GroupType;
import pl.register.android.group.StudentsGroup;
import pl.register.android.program.Program;
import pl.register.android.student.Student;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Mateusz Strzelecki
 * @since 2013-04-14
 */
public class Year implements Serializable {

    private Long id;

    private YearType yearType;

    private String subName;

    private Program program;


    private List<Student> students;

    private List<StudentsGroup> studentsGroups;

    public Year(Long id, YearType yearType, String subName) {
        this.id = id;
        this.yearType = yearType;
        this.subName = subName;

        students = new ArrayList<Student>();
        studentsGroups = new ArrayList<StudentsGroup>();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public YearType getType() {
        return yearType;
    }

    public void setYearType(YearType yearType) {
        this.yearType = yearType;
    }

    public String getSubName() {
        return subName;
    }

    public void setSubName(String subName) {
        this.subName = subName;
    }

    public Program getProgram() {
        return program;
    }

    public void setProgram(Program program) {
        this.program = program;
    }

    public List<StudentsGroup> getStudentsGroups() {
        return studentsGroups;
    }

    public void setStudentsGroups(List<StudentsGroup> studentsGroups) {
        this.studentsGroups = studentsGroups;
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }

    public void addStudent(Student student) {
        students.add(student);
    }

    public void deleteStudent(Student student) {
        students.remove(student);
    }

    public void addStudentToGroup(Student student, GroupType groupType) {
        if (studentsGroups != null && !studentsGroups.isEmpty()) {
            for (StudentsGroup group : studentsGroups) {
                if (group.getType().equals(groupType)) {
                    group.addStudent(student);
                    break;
                }
            }
        }
    }

    public void deleteStudentFromGroup(Student student, GroupType groupType) {
        if (studentsGroups != null && !studentsGroups.isEmpty()) {
            for (StudentsGroup group : studentsGroups) {
                if (group.getType().equals(groupType)) {
                    group.removeStudent(student);
                    break;
                }
            }
        }
    }

    @Override
    public String toString() {
        return "Year{" +
                "id=" + id +
                ", yearType='" + yearType + '\'' +
                ", subName='" + subName +
                '}';
    }
}
